<?php
class Articulos_model extends CI_Model {
    public function __construct() {
        $this->load->database();
    }
    
    public function get_articulos() {
        $query = $this->db->query("SELECT *
                                    FROM
                                        articulos
                                    ORDER BY
                                        idProducto,
                                        orden,
                                        codigo");
        return $query->result_array();
    }
    
    public function existe_articulo($codigo, $idMarca) {
        $query = $this->db->query("SELECT count(*) as cant
                                    FROM
                                        articulos
                                    WHERE
                                        codigo = '$codigo' AND
                                        idMarca = $idMarca");
        $res = $query->row_array();
        
        if($res['cant'] == 0) {
            return false;
        } else {
            return true;
        }
    }
    
    public function set_articulo($datos) {
        $this->db->insert('articulos', $datos);
    }
    
    public function get_articulo_por_id($idarticulo) {
        $query = $this->db->query("SELECT *
                                    FROM
                                        articulos
                                    WHERE
                                        idArticulo = $idarticulo");
        return $query->row_array();
    }
    
    public function get_cantidad_de_articulos() {
        $query = $this->db->query("SELECT COUNT(*) as cant
                                    FROM
                                        articulos");
        return $query->row_array();
    }
    
    public function update($datos, $id) {
        $id = array(
            'idArticulo' => $id
        );
        
        $this->db->update('articulos', $datos, $id);
    }
}
?>
